import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

//读操作（字符流）
public class Demo_8 {
    public static void main(String[] args) {
        try(Reader reader = new FileReader("./AAA.txt")){
            while (true){
                char[] buffer = new char[512];
                int n = reader.read(buffer);
                if(n==-1){
                    break;
                }
//                读法1
                String s = new String(buffer,0,n);
                System.out.println(s);

//                读法2
//                编码不同可能会出现乱码的情况
                for (int i = 0; i < n; i++) {
                    System.out.print(buffer[i]+" ");
                }

            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
